package com.lp.component_master;

import android.animation.FloatEvaluator;
import android.animation.ValueAnimator;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.lp.module_lib.api.BasePresenter;
import com.lp.module_lib.base.BaseActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 闪屏页面
 * 作者：created by LP_TREAM on 2020/11/26 22:23
 * 邮箱：806875201@qq.com
 */
public class SplashActivity extends BaseActivity {
    @BindView(R.id.iv_picture)
    ImageView mIvPicture;

    @Override
    protected BasePresenter createPresenter() {
        return null;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.app_activity_splash;
    }

    @Override
    protected void initData() {
        startAnimation();
    }

    private void startAnimation() {
        ValueAnimator animator = ValueAnimator.ofObject(new FloatEvaluator(), 1.0f, 1.2f);
        animator.setDuration(3000);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                Float value = (Float) animation.getAnimatedValue();
                if (value != 1.2f) {
                    mIvPicture.setScaleX(value);
                    mIvPicture.setScaleY(value);
                } else {
                    goToActivity();
                }
            }

            private void goToActivity() {
                Intent intent = new Intent(mContext, Main2Activity.class);
                startActivity(intent);
                overridePendingTransition(0, android.R.anim.fade_out);
                finish();
            }
        });
        animator.start();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ButterKnife.bind(this);
    }
}
